home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / util / gnu / WinGnuPlot.lha / WinGnuPlot / Source / Window.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-13  |  27.7 KB  |  781 lines

  1. #include "struct.c"
  2. #include "WinPlot.h"
  3. #include "OutlineFont.h"
  4. #include "amigawin.h"
  5.  
  6. /* like mui.h KeyButton, but with AmigaGuide node */
  7. #define KeyButtonGuide(name, key, helpnode)\
  8.     TextObject,\
  9.         ButtonFrame,\
  10.         MUIA_Text_Contents, name,\
  11.         MUIA_Text_PreParse, "\33c",\
  12.         MUIA_Text_SetMax  , FALSE,\
  13.         MUIA_Text_HiChar  , key,\
  14.         MUIA_ControlChar  , key,\
  15.         MUIA_InputMode    , MUIV_InputMode_RelVerify,\
  16.         MUIA_Background   , MUII_ButtonBack,\
  17.                 MUIA_HelpNode     , helpnode,\
  18.         End
  19.  
  20. #define CheckMarkGuide(selected, helpnode)\
  21.     ImageObject,\
  22.         ImageButtonFrame,\
  23.         MUIA_InputMode        , MUIV_InputMode_Toggle,\
  24.         MUIA_Image_Spec       , MUII_CheckMark,\
  25.         MUIA_Image_FreeVert   , TRUE,\
  26.         MUIA_Selected         , selected,\
  27.         MUIA_Background       , MUII_ButtonBack,\
  28.         MUIA_ShowSelState     , FALSE,\
  29.                 MUIA_HelpNode         , helpnode,\
  30.         End
  31.  
  32. #define CycleGuide(entries, helpnode)\
  33.         CycleObject,\
  34.          MUIA_Cycle_Entries , entries,\
  35.          MUIA_HelpNode      , helpnode,\ 
  36.         End
  37.  
  38. #define RangeObject(object, name)\
  39.          Child, Label2(name"Min:"),\
  40.          Child, object.Min = StringObject, MUIA_HelpNode, name"range", StringFrame, End,\
  41.          Child, Label2(name"Max:"),\
  42.          Child, object.Max = StringObject, MUIA_HelpNode, name"range", StringFrame, End,\
  43.          Child, Label("Auto_"name":"),\
  44.          Child, object.Auto = CheckMarkGuide(FALSE, "autoscale")
  45.  
  46. #define LogScaleObject(object, name)\
  47.          Child, Label("LogScale_"name":"),\
  48.          Child, object.LogScale = CheckMark(FALSE),\
  49.          Child, Label2("LogBase:"),\
  50.          Child, object.Base = StringObject, MUIA_Weight, 200, StringFrame, End
  51.  
  52. #define LabelObject(object, name)\
  53.          Child, Label(name),\
  54.          Child, object.Label = StringObject, StringFrame,\
  55.           MUIA_HelpNode, name,\
  56.          End,\
  57.          Child, Label("X"),\
  58.          Child, object.XOff = StringObject, StringFrame,\
  59.           MUIA_Weight, 50,\
  60.           MUIA_String_MaxLen, 6,\
  61.           MUIA_String_Integer, 0,\
  62.           MUIA_HelpNode, name,\
  63.          End,\
  64.          Child, Label("Y"),\
  65.          Child, object.YOff = StringObject, StringFrame,\
  66.           MUIA_Weight, 50,\
  67.           MUIA_String_MaxLen, 6,\
  68.           MUIA_String_Integer, 0,\
  69.           MUIA_HelpNode, name,\
  70.          End
  71.  
  72. #define WSpace(x) \
  73.          MUI_NewObject(MUIC_Rectangle, \
  74.                        MUIA_HorizWeight, 0, \
  75.                        MUIA_VertWeight, x, \
  76.                TAG_DONE)
  77.  
  78. /* set() without Notify */
  79. #define setnn(obj,attr,value) SetAttrs(obj,attr,value,MUIA_NoNotify,TRUE,TAG_DONE)
  80.  
  81. /* the ContourCycle labels */
  82. static char *ContourEntries[] =
  83. {
  84.  "no", "base", "surface", "both", NULL
  85. };
  86.  
  87. /* the Mapping labels */
  88. static char *MappingEntries[] =
  89. {
  90.  "cartesian", "spherical", "cylindrical", NULL
  91. };
  92.  
  93. /* the StyleCycle labels */
  94. char *StyleEntries[] =
  95. {
  96.  "lines", "points", "impulses", "linespoints", "dots", "errorbars", "boxes",
  97.  "boxerrorbars", "steps", NULL
  98. };
  99.  
  100. /* the Settings pagegroup labels */
  101. char *SetPages[] =
  102. {
  103.  "PlotRanges", "LogScales", "3D-Options", "Misc", "Fonts", "Labels", "Colors", 
  104.  "User Defined", NULL,
  105. };
  106.  
  107. /* the Gadget IDs */
  108. enum IDs
  109. {
  110.  ID_ReqOk=1, ID_Load, ID_Save, ID_CD, ID_NewFont, ID_Color, ID_About,
  111.  ID_Variable, ID_Function
  112. };
  113.  
  114. /* some simple menu */
  115. static struct NewMenu Menu[] =
  116. {
  117.  { NM_TITLE, "Project",   0,   0, 0, NULL},
  118.  { NM_ITEM,  "About...",  "?", 0, 0, (APTR)ID_About},
  119.  { NM_ITEM,  NM_BARLABEL, 0,   0, 0, 0},
  120.  { NM_ITEM,  "Load",      "L", 0, 0, (APTR)ID_Load},
  121.  { NM_ITEM,  "Save",      "S", 0, 0, (APTR)ID_Save},
  122.  { NM_ITEM,  "CD",        "C", 0, 0, (APTR)ID_CD},
  123.  { NM_ITEM,  NM_BARLABEL, 0,   0, 0, 0},
  124.  { NM_ITEM,  "Quit",      "Q", 0, 0, (APTR)MUIV_Application_ReturnID_Quit},
  125.  { NM_END,   NULL,        0,   0, 0, 0}
  126. };
  127.  
  128. /* the MUI objects */
  129.        APTR AP_WinPlot    = NULL; /* Application */
  130.        APTR WI_WinPlot    = NULL; /* Main window */
  131. static APTR WI_Settings   = NULL; /* Settings window */
  132. static APTR WI_Request    = NULL; /* Request window */
  133. static APTR BT_ReqOk      = NULL; /* Quit Requester button */
  134. static APTR BT_Plot       = NULL; /* Plot button */
  135. static APTR BT_Load       = NULL; /* Load button */
  136. static APTR BT_Save       = NULL; /* Save button */
  137. static APTR BT_CD         = NULL; /* CD button */
  138. static APTR BT_Set        = NULL; /* Settings button */
  139. static APTR LV_Font       = NULL; /* Font ListView */
  140. static APTR BO_Plot       = NULL; /* the Plot image itself */
  141. static APTR TO_Req        = NULL; /* Requester text */
  142. static APTR CY_Contour    = NULL; /* Contour gadget */
  143. static APTR CY_Function   = NULL; /* Function Style gadget */
  144. static APTR CY_Data       = NULL; /* Data Style gadget */
  145. static APTR CY_Mapping    = NULL; /* Mapping gadget */
  146. static APTR CM_Hidden3d   = NULL; /* Hidden3D button */
  147. static APTR CM_Surface    = NULL;
  148. static APTR SO_RotX       = NULL;
  149. static APTR SO_RotZ       = NULL;
  150. static APTR SO_Scale      = NULL;
  151. static APTR SO_ScaleZ     = NULL;
  152. static APTR SO_RePlot     = NULL; /* last plot command */
  153. static APTR PG_Set        = NULL; /* Settings pagegroup */
  154. static APTR CM_Parametric = NULL;
  155. static APTR CM_Polar      = NULL;
  156. static APTR CM_Grid       = NULL;
  157. static APTR CM_Border     = NULL;
  158. static APTR CM_XZero      = NULL;
  159. static APTR CM_YZero      = NULL;
  160. static APTR PO_Color      = NULL;
  161. static APTR BT_Color      = NULL;
  162. static APTR LV_Variable   = NULL; /* user defined variables */
  163. static APTR LV_Function   = NULL; /* user defined functions */
  164. static APTR SO_Variable   = NULL;
  165. static APTR SO_Function   = NULL;
  166.  
  167. static struct RangeObject    XRange, YRange, ZRange, RRange, TRange, URange, VRange;
  168. static struct LogScaleObject XLog, YLog, ZLog;
  169. static struct LabelObject    Title, XLabel, YLabel, ZLabel;
  170.  
  171. /* this routine freshes the plot, e.g. after a font change */
  172. void Refresh(void)
  173. {
  174.  struct Window *MainWindow;
  175.  struct Gadget *PlotGadget;
  176.  
  177.  get(WI_WinPlot, MUIA_Window_Window, &MainWindow);
  178.  get(BO_Plot, MUIA_Boopsi_Object, &PlotGadget);
  179.  if (MainWindow && PlotGadget)
  180.   RefreshGList(PlotGadget, MainWindow, NULL, 1);
  181. }
  182.  
  183. /* build the fontlist */
  184. static void InsertFonts(void)
  185. {
  186.  struct FileInfoBlock *fib;
  187.  
  188.  if (fib = AllocDosObject(DOS_FIB, NULL))
  189.   {
  190.    BPTR lock;
  191.  
  192.    if (lock = Lock("FONTS:", ACCESS_READ))
  193.     {
  194.      Examine(lock, fib);
  195.      while (ExNext(lock, fib) && (IoErr() != ERROR_NO_MORE_ENTRIES))
  196.       DoMethod(LV_Font, MUIM_List_InsertSingle, fib, MUIV_List_Insert_Sorted);
  197.      
  198.      UnLock(lock);
  199.     }
  200.    FreeDosObject(DOS_FIB, fib);
  201.   }
  202. }
  203.  
  204. /* Notifation for a RangeObject */
  205. static void NotifyRange(APTR GUI, struct RangeObject *ro, char *name, char *command)
  206. {
  207.  DoMethod(ro->Min, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  208.       GUI, 4, MUIM_CallHook, &RangeHook, ro, name);
  209.  DoMethod(ro->Max, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  210.       GUI, 4, MUIM_CallHook, &RangeHook, ro, name);
  211.  DoMethod(ro->Auto, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  212.       ro->Auto, 3, MUIM_CallHook, &CheckHook, command);
  213. }
  214.  
  215. /* Notification for a LogScaleObject */
  216. static void NotifyLogScale(APTR GUI, struct LogScaleObject *lco, char *command)
  217. {
  218.  DoMethod(lco->LogScale, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  219.       lco->LogScale, 4, MUIM_CallHook, &LogScaleHook, lco, command);
  220.  DoMethod(lco->Base, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  221.       GUI, 4, MUIM_CallHook, &LogScaleHook, lco, command);
  222. }
  223.  
  224. /* Notification for a LabelObject */
  225. static void NotifyLabel(APTR GUI, struct LabelObject *lo, char *title)
  226. {
  227.  DoMethod(lo->Label, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  228.       GUI, 4, MUIM_CallHook, &LabelHook, lo, title);
  229.  DoMethod(lo->XOff, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  230.       GUI, 4, MUIM_CallHook, &LabelHook, lo, title);
  231.  DoMethod(lo->YOff, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  232.       GUI, 4, MUIM_CallHook, &LabelHook, lo, title);
  233. }
  234.  
  235. /* Build the GUI */
  236. APTR GetGUI(void)
  237. {
  238.  APTR GUI;
  239.  
  240.  GUI = ApplicationObject,
  241.     MUIA_Application_Title, "WinPlot",
  242.     MUIA_Application_Version, "$VER: WinPlot 1.2  "__AMIGADATE__,
  243.         MUIA_Application_Copyright, "Copyright © 1993 by Michael Illgner",
  244.         MUIA_Application_Author, "Michael Illgner",
  245.         MUIA_Application_Description, "A MUI GnuPlot Frontend",
  246.         MUIA_Application_Base, "WINPLOT",
  247.         MUIA_Application_SingleTask, TRUE,
  248.         MUIA_Application_Menu, Menu,
  249.     MUIA_HelpFile, "PROGDIR:gnuplot.guide",
  250.         SubWindow, WI_WinPlot = WindowObject,
  251.          MUIA_Window_Title, "WinPlot",
  252.          MUIA_Window_ID,MAKE_ID('P','L','O','T'),
  253.          WindowContents, VGroup, 
  254.           Child, HGroup, GroupFrame,
  255.            MUIA_Group_SameSize, TRUE,
  256.            Child, BT_Plot = KeyButtonGuide("RePlot", 'p', "replot"),
  257.        Child, BT_Load = KeyButtonGuide("Load", 'l', "load"),
  258.        Child, BT_Save = KeyButtonGuide("Save", 's', "save"),
  259.        Child, BT_CD   = KeyButtonGuide("CD", 'c', "cd"),
  260.            Child, BT_Set  = KeyButtonGuide("Edit",'e', "set-show"),
  261.           End,
  262.           Child, BO_Plot = BoopsiObject,
  263.            GroupFrame,
  264.            MUIA_Boopsi_Class, PlotImgClass,
  265.            MUIA_Boopsi_MinWidth, 30,
  266.            MUIA_Boopsi_MinHeight, 30,
  267.            GA_LEFT, 0,
  268.            GA_TOP, 0,
  269.            GA_WIDTH, 0,
  270.            GA_HEIGHT, 0,
  271.           End,
  272.          End,
  273.         End,
  274.         SubWindow, WI_Request = WindowObject,
  275.          MUIA_Window_Title, "WinPlot Requester",
  276.          MUIA_Window_SizeGadget, FALSE,
  277.          MUIA_Window_CloseGadget, FALSE,
  278.          WindowContents, VGroup,
  279.        MUIA_Background, MUII_RequesterBack,
  280.           Child, TO_Req = TextObject, TextFrame,
  281.        MUIA_Background, MUII_TextBack,
  282.            MUIA_Text_PreParse, "\33c",
  283.           End,
  284.       Child, BT_ReqOk = TextObject,
  285.            ButtonFrame,
  286.        MUIA_Text_Contents, "Ok",
  287.            MUIA_Text_PreParse, "\33c",
  288.            MUIA_Text_SetMax, TRUE,
  289.            MUIA_Text_HiChar, '\r',
  290.            MUIA_ControlChar, '\r',
  291.            MUIA_InputMode, MUIV_InputMode_RelVerify,
  292.            MUIA_Background, MUII_ActiveBack,
  293.           End,
  294.          End,
  295.         End,
  296.         SubWindow, WI_Settings = WindowObject,
  297.          MUIA_Window_Title, "GnuPlot settings",
  298.          MUIA_Window_ID, MAKE_ID('P','S','E','T'),
  299.          MUIA_HelpNode, "set-show",
  300.          WindowContents, VGroup,
  301.           Child, PG_Set = RegisterGroup(SetPages), MUIA_Register_Frame, TRUE,
  302.            Child, VGroup,
  303.             Child, WSpace(100), 
  304.             Child, ColGroup(6),
  305.              RangeObject(XRange, "X"),
  306.              RangeObject(YRange, "Y"),
  307.              RangeObject(ZRange, "Z"),
  308.              RangeObject(RRange, "R"),
  309.              RangeObject(TRange, "T"),
  310.              RangeObject(URange, "U"),
  311.              RangeObject(VRange, "V"),
  312.             End,
  313.             Child, WSpace(100),
  314.            End,
  315.            Child, VGroup,
  316.             Child, WSpace(100),
  317.             Child, ColGroup(4), MUIA_HelpNode, "logscale",
  318.              LogScaleObject(XLog, "X"),
  319.              LogScaleObject(YLog, "Y"),
  320.              LogScaleObject(ZLog, "Z"),
  321.             End,
  322.  Child, WSpace(100),
  323.            End,
  324.            Child, VGroup,
  325.             Child, WSpace(100),
  326.             Child, VGroup,
  327.              Child, ColGroup(4),
  328.               Child, HSpace(0),
  329.               Child, Label("Contour:"),
  330.               Child, CY_Contour = CycleGuide(ContourEntries, "contour"),
  331.               Child, HSpace(0),
  332.               Child, HSpace(0),
  333.               Child, Label("Mapping:"),
  334.               Child, CY_Mapping = CycleGuide(MappingEntries, "mapping"),
  335.               Child, HSpace(0),
  336.              End,
  337.              Child, WSpace(50),
  338.              Child, ColGroup(4),
  339.               Child, HSpace(0),
  340.               Child, Label("Hidden3D:"),
  341.               Child, CM_Hidden3d = CheckMarkGuide(FALSE, "hidden3d"),
  342.               Child, HSpace(0),
  343.               Child, HSpace(0),
  344.               Child, Label("Surface"),
  345.               Child, CM_Surface = CheckMarkGuide(FALSE, "surface"),
  346.               Child, HSpace(0),
  347.              End,
  348.              Child, WSpace(50),
  349.              Child, ColGroup(2),
  350.               Child, Label("Rotation_X:"),
  351.               Child, SO_RotX = StringObject, StringFrame,
  352.                MUIA_HelpNode, "view",
  353.               End,
  354.               Child, Label("Rotation_Z:"),
  355.               Child, SO_RotZ = StringObject, StringFrame,
  356.                MUIA_HelpNode, "view",
  357.               End,
  358.               Child, Label("Scale:"),
  359.               Child, SO_Scale = StringObject, StringFrame,
  360.                MUIA_HelpNode, "view",
  361.               End,
  362.               Child, Label("Scale_Z:"),
  363.               Child, SO_ScaleZ = StringObject, StringFrame,
  364.                MUIA_HelpNode, "view",
  365.               End,
  366.              End,
  367.             End,
  368.             Child, WSpace(100),
  369.            End,
  370.            Child, VGroup,
  371.             Child, WSpace(100),
  372.             Child, ColGroup(6),
  373.              Child, HSpace(0),
  374.              Child, Label("Functionstyle:"),
  375.              Child, CY_Function = CycleGuide(StyleEntries, "style"),
  376.              Child, Label("Datastyle:"),
  377.              Child, CY_Data = CycleGuide(StyleEntries, "style"),
  378.              Child, HSpace(0),
  379.              Child, HSpace(0),
  380.              Child, WSpace(25),
  381.              Child, WSpace(25),
  382.              Child, WSpace(25),
  383.              Child, WSpace(25),
  384.              Child, HSpace(0),
  385.              Child, HSpace(0),
  386.              Child, Label("Parametric:"),
  387.              Child, CM_Parametric = CheckMarkGuide(FALSE, "parametric"),
  388.              Child, Label("Polar:"),
  389.              Child, CM_Polar = CheckMarkGuide(FALSE, "polar"),
  390.              Child, HSpace(0),
  391.              Child, HSpace(0),
  392.              Child, Label("Grid:"),
  393.              Child, CM_Grid = CheckMarkGuide(FALSE, "grid"),
  394.              Child, Label("Border:"),
  395.              Child, CM_Border = CheckMarkGuide(FALSE, "border"),
  396.              Child, HSpace(0),
  397.              Child, HSpace(0),
  398.              Child, Label("xzeroaxis"),
  399.              Child, CM_XZero = CheckMarkGuide(FALSE, "xzeroaxis"),
  400.              Child, Label("yzeroaxis"),
  401.              Child, CM_YZero = CheckMarkGuide(FALSE, "yzeroaxis"),
  402.              Child, HSpace(0),
  403.             End,
  404.             Child, WSpace(100),
  405.            End,
  406.            Child, LV_Font = ListviewObject, InputListFrame,
  407.             MUIA_Listview_List, ListObject,
  408.              MUIA_List_ConstructHook, &ConFontHook,
  409.              MUIA_List_DestructHook, &DesFontHook,
  410.              MUIA_ExportID, 1,
  411.             End,
  412.            End,
  413.            Child, VGroup,
  414.             Child, WSpace(100),
  415.             Child, ColGroup(6),
  416.              LabelObject(Title, "Title"),
  417.              LabelObject(XLabel, "XLabel"),
  418.              LabelObject(YLabel, "YLabel"),
  419.              LabelObject(ZLabel, "ZLabel"),
  420.             End,
  421.             Child, WSpace(100),
  422.            End,
  423.            Child, VGroup,
  424.             Child, WSpace(100),
  425.             Child, PO_Color = PaletteObject, GroupFrame,
  426.              MUIA_Palette_Entries, ColorEntries,
  427.              MUIA_Palette_Names, ColorNames,
  428.             End,
  429.             Child, WSpace(50),
  430.             Child, BT_Color = KeyButton("Change Colors", 'c'),
  431.             Child, WSpace(100),
  432.            End,
  433.            Child, VGroup,
  434.             MUIA_HelpNode, "user-defined",
  435.             Child, VGroup, InputListFrame,
  436.              Child, LV_Variable = ListviewObject,
  437.               MUIA_FrameTitle, "User defined Variables",
  438.               MUIA_Listview_List, ListObject,
  439.                MUIA_List_ConstructHook, &ConVarHook,
  440.                MUIA_List_DestructHook, &DesVarHook,
  441.               End,
  442.              End,
  443.              Child, VSpace(1),
  444.              Child, SO_Variable = StringObject, StringFrame, 
  445.               MUIA_String_AttachedList, LV_Variable,
  446.              End,
  447.             End,
  448.             Child, VSpace(5),
  449.             Child, VGroup, InputListFrame,
  450.              Child, LV_Function = ListviewObject,
  451.               MUIA_FrameTitle, "User defined Functions",
  452.               MUIA_Listview_List, ListObject, End,
  453.              End,
  454.              Child, VSpace(1),
  455.              Child, SO_Function = StringObject, StringFrame,
  456.               MUIA_String_AttachedList, LV_Function,
  457.               End,
  458.             End,
  459.            End,
  460.           End,
  461.           Child, SO_RePlot = StringObject,
  462.            MUIA_Frame, MUIV_Frame_String,
  463.            MUIA_FrameTitle, "Last Plot",
  464.            MUIA_HelpNode, "plot",
  465.           End,
  466.          End,
  467.         End,
  468.        End;
  469.  
  470.  if (GUI)
  471.   {
  472.    char *RealFontName;
  473.    int   Active;
  474.    
  475.    InsertFonts();
  476.    DoMethod(WI_WinPlot, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  477.         GUI, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  478.    DoMethod(BT_Plot, MUIM_Notify, MUIA_Pressed, FALSE,
  479.         GUI, 3, MUIM_CallHook, &RexxCommandHook, "replot");
  480.    DoMethod(BT_Load, MUIM_Notify, MUIA_Pressed, FALSE,
  481.         GUI, 2, MUIM_Application_ReturnID, ID_Load);
  482.    DoMethod(BT_Save, MUIM_Notify, MUIA_Pressed, FALSE,
  483.         GUI, 2, MUIM_Application_ReturnID, ID_Save);
  484.    DoMethod(BT_CD, MUIM_Notify, MUIA_Pressed, FALSE,
  485.         GUI, 2, MUIM_Application_ReturnID, ID_CD);
  486.    DoMethod(LV_Font, MUIM_Notify, MUIA_Listview_DoubleClick, TRUE,
  487.         GUI, 2, MUIM_Application_ReturnID, ID_NewFont);
  488.    DoMethod(BT_ReqOk, MUIM_Notify, MUIA_Pressed, FALSE,
  489.         GUI, 2, MUIM_Application_ReturnID, ID_ReqOk);
  490.    DoMethod(BT_Set, MUIM_Notify, MUIA_Pressed, FALSE,
  491.         WI_Settings, 3, MUIM_Set, MUIA_Window_Open, TRUE);
  492.    DoMethod(WI_Settings, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  493.             WI_Settings, 3, MUIM_Set, MUIA_Window_Open, FALSE);
  494.    NotifyRange(GUI, &XRange, "xrange", "set %sautoscale x");
  495.    NotifyRange(GUI, &YRange, "yrange", "set %sautoscale y");
  496.    NotifyRange(GUI, &ZRange, "zrange", "set %sautoscale z");
  497.    NotifyRange(GUI, &RRange, "rrange", "set %sautoscale r");
  498.    NotifyRange(GUI, &TRange, "trange", "set %sautoscale t");
  499.    NotifyRange(GUI, &URange, "urange", "set %sautoscale u");
  500.    NotifyRange(GUI, &VRange, "vrange", "set %sautoscale v");
  501.    DoMethod(CM_Hidden3d, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  502.         CM_Hidden3d, 3, MUIM_CallHook, &CheckHook, "set %shidden3d");
  503.    DoMethod(CM_Parametric, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  504.         CM_Parametric, 3, MUIM_CallHook, &CheckHook, "set %sparametric");
  505.    DoMethod(CM_Polar, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  506.         CM_Polar, 3, MUIM_CallHook, &CheckHook, "set %spolar");
  507.    DoMethod(CM_Grid, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  508.         CM_Grid, 3, MUIM_CallHook, &CheckHook, "set %sgrid");
  509.    DoMethod(CM_Border, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  510.         CM_Border, 3, MUIM_CallHook, &CheckHook, "set %sborder");
  511.    DoMethod(CM_XZero, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  512.         CM_XZero, 3, MUIM_CallHook, &CheckHook, "set %sxzeroaxis");
  513.    DoMethod(CM_YZero, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  514.         CM_YZero, 3, MUIM_CallHook, &CheckHook, "set %syzeroaxis");
  515.    DoMethod(CM_Surface, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  516.         CM_Surface, 3, MUIM_CallHook, &CheckHook, "set %ssurface");
  517.    DoMethod(CY_Contour, MUIM_Notify, MUIA_Cycle_Active, 0,
  518.             GUI, 3, MUIM_CallHook, &RexxCommandHook, "set nocontour");
  519.    DoMethod(CY_Contour, MUIM_Notify, MUIA_Cycle_Active, 1,
  520.             GUI, 3, MUIM_CallHook, &RexxCommandHook, "set contour base");
  521.    DoMethod(CY_Contour, MUIM_Notify, MUIA_Cycle_Active, 2,
  522.             GUI, 3, MUIM_CallHook, &RexxCommandHook, "set contour surface");
  523.    DoMethod(CY_Contour, MUIM_Notify, MUIA_Cycle_Active, 3,
  524.             GUI, 3, MUIM_CallHook, &RexxCommandHook, "set contour both");
  525.    DoMethod(CY_Mapping, MUIM_Notify, MUIA_Cycle_Active, 0,
  526.         GUI, 3, MUIM_CallHook, &RexxCommandHook, "set mapping cartesian");
  527.    DoMethod(CY_Mapping, MUIM_Notify, MUIA_Cycle_Active, 1,
  528.         GUI, 3, MUIM_CallHook, &RexxCommandHook, "set mapping spherical");
  529.    DoMethod(CY_Mapping, MUIM_Notify, MUIA_Cycle_Active, 2,
  530.         GUI, 3, MUIM_CallHook, &RexxCommandHook, "set mapping cylindrical");
  531.    DoMethod(SO_RotX, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  532.         SO_RotX, 3, MUIM_CallHook, &ViewHook, "set view %s");
  533.    DoMethod(SO_RotZ, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  534.         SO_RotZ, 3, MUIM_CallHook, &ViewHook, "set view ,%s");
  535.    DoMethod(SO_Scale, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  536.         SO_Scale, 3, MUIM_CallHook, &ViewHook, "set view ,,%s");
  537.    DoMethod(SO_ScaleZ, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  538.         SO_ScaleZ, 3, MUIM_CallHook, &ViewHook, "set view ,,,%s");
  539.    DoMethod(CY_Function, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
  540.         CY_Function, 3, MUIM_CallHook, &StyleHook, "set function style %s");
  541.    DoMethod(CY_Data, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
  542.         CY_Data, 3, MUIM_CallHook, &StyleHook, "set data style %s");
  543.    NotifyLogScale(GUI, &XLog, "set %slogscale x %s");
  544.    NotifyLogScale(GUI, &YLog, "set %slogscale y %s");
  545.    NotifyLogScale(GUI, &ZLog, "set %slogscale z %s");
  546.    NotifyLabel(GUI, &Title, "title");
  547.    NotifyLabel(GUI, &XLabel, "xlabel");
  548.    NotifyLabel(GUI, &YLabel, "ylabel");
  549.    NotifyLabel(GUI, &ZLabel, "zlabel");
  550.    DoMethod(SO_RePlot, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  551.         SO_RePlot, 2, MUIM_CallHook, &StringCommandHook);
  552.    DoMethod(BT_Color, MUIM_Notify, MUIA_Pressed, FALSE,
  553.         GUI, 2, MUIM_Application_ReturnID, ID_Color);
  554.    DoMethod(LV_Variable ,MUIM_Notify, MUIA_Listview_DoubleClick, TRUE,
  555.         GUI, 2, MUIM_Application_ReturnID, ID_Variable);
  556.    DoMethod(SO_Variable, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  557.         SO_Variable, 2, MUIM_CallHook, &StringCommandHook);
  558.    DoMethod(LV_Function ,MUIM_Notify, MUIA_Listview_DoubleClick, TRUE,
  559.         GUI, 2, MUIM_Application_ReturnID, ID_Function);
  560.    DoMethod(SO_Function, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  561.         SO_Function, 2, MUIM_CallHook, &StringCommandHook);
  562.  
  563.    DoMethod(GUI, MUIM_Application_Load, CONFIG);
  564.    get(LV_Font, MUIA_List_Active, &Active);
  565.    if (Active == -1)
  566.     set(LV_Font, MUIA_List_Active, 0);
  567.    DoMethod(LV_Font, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &RealFontName);
  568.    OpenOutlineFont(RealFontName);
  569.  
  570.    DoMethod(WI_Settings, MUIM_Window_SetCycleChain,
  571.         SO_RePlot, PG_Set,
  572.         XRange.Min, XRange.Max, XRange.Auto,
  573.         YRange.Min, YRange.Max, YRange.Auto,
  574.         ZRange.Min, ZRange.Max, ZRange.Auto,
  575.         RRange.Min, RRange.Max, RRange.Auto,
  576.         TRange.Min, TRange.Max, TRange.Auto,
  577.         URange.Min, URange.Max, URange.Auto,
  578.         VRange.Min, VRange.Max, VRange.Auto,
  579.         XLog.LogScale, XLog.Base,
  580.         YLog.LogScale, YLog.Base,
  581.         ZLog.LogScale, ZLog.Base,
  582.         CY_Contour, CY_Mapping, CM_Hidden3d, CM_Surface,
  583.         SO_RotX, SO_RotZ, SO_Scale, SO_ScaleZ,
  584.         CY_Data, CY_Function,
  585.             CM_Parametric, CM_Polar, CM_Grid, CM_Border, CM_XZero, CM_YZero,
  586.         LV_Font,
  587.         Title.Label, Title.XOff, Title.YOff,
  588.         XLabel.Label, XLabel.XOff, XLabel.YOff,
  589.         YLabel.Label, YLabel.XOff, YLabel.YOff,
  590.         ZLabel.Label, ZLabel.XOff, ZLabel.YOff,
  591.             PO_Color, BT_Color,
  592.         LV_Variable, SO_Variable,
  593.         LV_Function, SO_Function,
  594.             NULL);
  595.   }
  596.  
  597.  return GUI;
  598. }
  599.  
  600. /* the 'please press <return>' requester */
  601. /* it looks like a requester, but is in fact a window */
  602. void WaitRequest(char *Text)
  603. {
  604.  BOOL Quit = FALSE;
  605.  
  606.  
  607.  set(TO_Req, MUIA_Text_Contents, Text);
  608.  set(WI_Request, MUIA_Window_Open, TRUE);
  609.  
  610.  /* disable the mainbuttons */
  611.  DoMethod(WI_Request, MUIM_MultiSet, MUIA_Disabled, TRUE, BT_Plot, BT_CD, BT_Load, BT_Save, NULL);
  612.  
  613.  while (!Quit)
  614.   {
  615.    ULONG ID, Signals;
  616.    
  617.    ID = DoMethod(AP_WinPlot, MUIM_Application_Input, &Signals);
  618.    switch (ID)
  619.     {
  620.     case ID_ReqOk:
  621.      Quit = TRUE;
  622.      break;
  623.     }
  624.    if (Signals) Wait(Signals);
  625.   }
  626.  
  627.  /* enable the main buttons */
  628.  DoMethod(WI_Request, MUIM_MultiSet, MUIA_Disabled, FALSE, BT_Plot, BT_CD, BT_Load, BT_Save, NULL);
  629.  
  630.  set(WI_Request, MUIA_Window_Open, FALSE);
  631. }
  632.  
  633. /* set StringObject to double*/
  634. static void SetString(APTR so, double val)
  635. {
  636.  char Buffer[255];
  637.  
  638.  sprintf(Buffer, "%lg", val);
  639.  setnn(so, MUIA_String_Contents, Buffer);
  640.  setnn(so, MUIA_String_BufferPos, 0);
  641. }
  642.  
  643. /* set RangeObject values */
  644. static void SetRange(struct RangeObject ro, double min, double max, BOOL autorange)
  645. {
  646.  SetString(ro.Min, min);
  647.  SetString(ro.Max, max);
  648. }
  649.  
  650. /* set LogScaleObject values */
  651. static void SetLogScale(struct LogScaleObject lco, double base, BOOL logscale)
  652. {
  653.  if (base != 0.0)
  654.   SetString(lco.Base, base);
  655.  setnn(lco.LogScale, MUIA_Selected, logscale);
  656. }
  657.  
  658. /* set LabelObject values */
  659. static void SetLabel(struct LabelObject lo, char *Title, int XOff, int YOff)
  660. {
  661.  setnn(lo.Label, MUIA_String_Contents, Title);
  662.  setnn(lo.Label, MUIA_String_BufferPos, 0);
  663.  setnn(lo.XOff, MUIA_String_Integer, XOff);
  664.  setnn(lo.YOff, MUIA_String_Integer, YOff);
  665. }
  666.  
  667. void Settings(struct SetVar *sv)
  668. {
  669.  udvt_entry *udv;
  670.  udft_entry *udf;
  671.  
  672.  if (sv)
  673.   {
  674.    SetRange(XRange, sv->xmin, sv->xmax, sv->autox);
  675.    SetRange(YRange, sv->ymin, sv->ymax, sv->autoy);
  676.    SetRange(ZRange, sv->zmin, sv->zmax, sv->autoz);
  677.    SetRange(RRange, sv->rmin, sv->rmax, sv->autor);
  678.    SetRange(TRange, sv->tmin, sv->tmax, sv->autot);
  679.    SetRange(URange, sv->umin, sv->umax, sv->autou);
  680.    SetRange(VRange, sv->vmin, sv->vmax, sv->autov);
  681.  
  682.    SetLogScale(XLog, sv->basex, sv->logx);
  683.    SetLogScale(YLog, sv->basey, sv->logy);
  684.    SetLogScale(ZLog, sv->basez, sv->logz);
  685.  
  686.    setnn(CY_Contour, MUIA_Cycle_Active, sv->contour);
  687.    setnn(CY_Mapping, MUIA_Cycle_Active, sv->mapping);
  688.    setnn(CM_Hidden3d, MUIA_Selected, sv->hidden3d);
  689.    setnn(CM_Surface, MUIA_Selected, sv->surface);
  690.    SetString(SO_RotX, sv->rotx);
  691.    SetString(SO_RotZ, sv->rotz);
  692.    SetString(SO_Scale, sv->scale);
  693.    SetString(SO_ScaleZ, sv->zscale);
  694.    setnn(CY_Function, MUIA_Cycle_Active, sv->functionstyle);
  695.    setnn(CY_Data, MUIA_Cycle_Active, sv->datastyle);
  696.    
  697.    setnn(CM_Parametric, MUIA_Selected, sv->parametric);
  698.    setnn(CM_Polar, MUIA_Selected, sv->polar);
  699.    setnn(CM_Grid, MUIA_Selected, sv->grid);
  700.    setnn(CM_Border, MUIA_Selected, sv->border);
  701.    setnn(CM_XZero, MUIA_Selected, sv->xzeroaxis);
  702.    setnn(CM_YZero, MUIA_Selected, sv->yzeroaxis);
  703.  
  704.    SetLabel(Title, sv->title, sv->title_xoff, sv->title_yoff);
  705.    SetLabel(XLabel, sv->xlabel, sv->xlabel_xoff, sv->xlabel_yoff);
  706.    SetLabel(YLabel, sv->ylabel, sv->ylabel_xoff, sv->ylabel_yoff);
  707.    SetLabel(ZLabel, sv->zlabel, sv->zlabel_xoff, sv->zlabel_yoff);
  708.  
  709.    setnn(SO_RePlot, MUIA_String_Contents, sv->replot);
  710.    setnn(SO_RePlot, MUIA_String_BufferPos, 0);
  711.  
  712.    set(LV_Variable, MUIA_List_Quiet, TRUE);
  713.    DoMethod(LV_Variable, MUIM_List_Clear);
  714.    for(udv = sv->user_variables; udv; udv=udv->next_udv)
  715.     DoMethod(LV_Variable, MUIM_List_InsertSingle, udv, MUIV_List_Insert_Bottom);
  716.    set(LV_Variable, MUIA_List_Quiet, FALSE);
  717.  
  718.    set(LV_Function, MUIA_List_Quiet, TRUE);
  719.    DoMethod(LV_Function, MUIM_List_Clear);
  720.    for(udf = sv->user_functions; udf; udf=udf->next_udf)
  721.     DoMethod(LV_Function, MUIM_List_InsertSingle, udf->definition, MUIV_List_Insert_Bottom);
  722.    set(LV_Function, MUIA_List_Quiet, FALSE);
  723.   }
  724. }
  725.  
  726. BOOL HandleMUI(ULONG Id)
  727. {
  728.  BOOL   Quit = FALSE;
  729.  char  *s;
  730.  
  731.  switch(Id)
  732.   {
  733.   case MUIV_Application_ReturnID_Quit:
  734.    if (MUI_Request(AP_WinPlot, NULL, 0, NULL, "Ok|*Cancel", "Do you really want to quit ?!"))
  735.     {
  736.      if (FindPort(GNUREPLY))
  737.       SendRexxMsg("quit");
  738.      else Quit = TRUE;
  739.     }
  740.    break;
  741.   case ID_NewFont:
  742.    DoMethod(LV_Font, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &s);
  743.    CloseOutlineFont();
  744.    OpenOutlineFont(s);
  745.    Refresh();
  746.    break;
  747.   case ID_Load:
  748.    LoadFunc();
  749.    break;
  750.   case ID_Save:
  751.    SaveFunc();
  752.    break;
  753.   case ID_CD:
  754.    CDFunc();
  755.    break;
  756.   case ID_Color:
  757.    Refresh();
  758.    break;
  759.   case ID_About:
  760.    MUI_Request(AP_WinPlot, NULL, 0, NULL, "OK",
  761.            "\033c\0338WinPlot\n\n"
  762.            "\0332Version 1.2  ("__DATE__")\n"
  763.            "Copyright 1994 by Michael Illgner.\n"
  764.            "\nThis is a MUI-Application.\n"
  765.            "MUI is copyrighted by Stefan Stuntz.");
  766.    break;
  767.   case ID_Variable:
  768.    DoMethod(LV_Variable, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &s);
  769.    set(SO_Variable, MUIA_String_Contents, s);
  770.    break;
  771.   case ID_Function:
  772.    DoMethod(LV_Function, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &s);
  773.    set(SO_Function, MUIA_String_Contents, s);
  774.    break;
  775.   default:
  776.    break;
  777.   }
  778.  
  779.  return Quit;
  780. }
  781.